package com.atguigu.gmall.common.config;

import com.atguigu.gmall.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author XIN
 * 2023/4/17
 */
@Slf4j
@ResponseBody
@ControllerAdvice
public class GlobalExceptionHandler {
	@ExceptionHandler(RuntimeException.class)
	public Result exception(RuntimeException runtimeException){
	log.error("全局异常RuntimeException处理:{}",runtimeException);
	return Result.fail().message(runtimeException.getMessage());
	}
	@ExceptionHandler(Exception.class)
	public Result exception(Exception e){
		log.error("全局异常Exception处理:{}",e);
		return Result.fail().message(e.getMessage());
	}
}
